package com.chucang.shucang.common.security.feignconfig;

import feign.RequestInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.security.oauth2.server.resource.web.BearerTokenResolver;

/**
 * @author flitsneak
 * @email flitsneak@gmail.com
 * @date 2022/9/24 19:23
 * @description feign配置
 */
@ConditionalOnProperty(name = "oauth2.resource.sever.enabled", havingValue = "true")
public class FeignClientConfig {
    /**
     * 注入 oauth2 feign token 增强
     *
     * @param tokenResolver token获取处理器
     * @return feign拦截器
     */
    @Bean
    public RequestInterceptor oauthRequestInterceptor(BearerTokenResolver tokenResolver) {
        return new OAuthFeignRequestInterceptor(tokenResolver);
    }
}
